package com.ldd.malphite.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

import java.util.concurrent.*;

@RestController
@RequestMapping("/thread")
public class ThreadController {


    /*
        串行改并行，适用于首页大屏信息等
    * https://mp.weixin.qq.com/s/IMRBOOm3j23XJda_jlwG3g*/
    public Map<String,Object> a(){
        ExecutorService executorService = Executors.newFixedThreadPool(20);
        ExecutorCompletionService service = new ExecutorCompletionService(executorService);
        //获取所有用户
        service.submit(()->{
            return "";
        });
        //获取所有分类
        service.submit(()->{
            return "";
        });
        //获取所有的钱
        service.submit(()->{
            return "";
        });

        for(int i=0;i<3;i++){
            try {
                Object o = service.poll().get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

}
